import { ApiCall } from "tsrpc";
import { ReqCreateQuestion, ResCreateQuestion } from "../../shared/protocols/QuestionsSys/PtlCreateQuestion";
import { Global } from '../../Global/index';

export default async function (call: ApiCall<ReqCreateQuestion, ResCreateQuestion>) {
    // TODO
    const teahcer = call.currentUser

    const question = {
        question:call.req.question,
        answer:call.req.answer,
        teacher:teahcer._id,
    }
    
    const ret = await Global.collection('questions').insertOne(question);

    call.succ({
        question:{
            ...question,
            _id:ret.insertedId
        }
    })
}